package com.atguigu.tingshu.cdc;

import com.atguigu.tingshu.model.CDCEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import top.javatool.canal.client.annotation.CanalTable;
import top.javatool.canal.client.handler.EntryHandler;

/**
 * @author: atguigu
 * @create: 2024-03-05 11:36
 */
@Slf4j
@Component
@CanalTable("user_info")
public class UserCdcHandler implements EntryHandler<CDCEntity> {


    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 监听到用户信息表更新操作
     *
     * @param before
     * @param after
     */
    @Override
    public void update(CDCEntity before, CDCEntity after) {
        log.info("监听到用户更新：{}", after.getId());
        redisTemplate.delete("user:" + after.getId());
    }
}
